﻿using System.Web.Mvc;
using Site.Models;

namespace Site.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index(CredentialsDTO model)
        {
            return View();
        }

        public ActionResult Register()
        {
            return View("Register");
        }
        public ActionResult RegisterUser(RegisterDTO model)
        {
            if (model.RegisterUser())
                return View("Index");

            ViewBag.Message = "User already exists";
            return View("Register");
        }
        public ActionResult Login(LoginDTO model)
        {
            if (model.ValidUser)
                Session["Username"] = model.Username;
            else
                ViewBag.Message = "Invalid user credentials";
            return View("Index");
            
        }

        public ActionResult Logout()
        {
            Session["Username"] = null;
            return View("Index");
        }
    }
}
